package main

import (
	"compress/gzip"
	"fmt"
	"os"
)

func main() {

	file := "1.txt"
	f, err := os.Create(file)
	if err != nil {
		fmt.Println("open file failed:", err)
		return
	}

	defer f.Close()
	zw := gzip.NewWriter(f)
	defer zw.Close()

	_, err = zw.Write([]byte("hello go"))
	if err != nil {
		fmt.Println("write compressed data error:", err)

	}

}
